<script setup lang="ts">
import { OrderStatus } from '@/enum'
import { getMedicineDetailPay } from '@/services/medicine'
import { useConsultStore } from '@/stores'
import type { OrderDetail } from '@/types/medicine'
import { onMounted, ref } from 'vue'
import { useRoute } from 'vue-router'

const route = useRoute()
const order = ref<OrderDetail>()
console.log(route.query.orderId)

// 获取支付结果
// ??? 订单类型错误
onMounted(async () => {
  const data = await getMedicineDetailPay(route.query.orderId as string)
  console.log(data)
  order.value = data.data
})
const consult = useConsultStore()
const roomConfig = consult.routeConfig
</script>

<template>
  <div class="pay-result-page">
    <DP-NavBar
      title="药品支付结果"
      :back="
        () => {
          $router.push({ name: 'home' })
        }
      "
    ></DP-NavBar>
    <div class="content" v-if="order?.status === OrderStatus.MedicinePay">
      <van-icon name="clear" color="#68c1a1" size="60" />
      <p class="price">￥{{ order.actualPayment.toFixed(2) }}</p>
      <p>支付失败</p>
      <p class="success" style="margin-top: 20px">
        订单支付失败，可以点击查看订单继续支付，如有疑问联系客服
      </p>
      <div class="btn">
        <van-button type="primary" :to="`/order/${order?.id}`"
          >查看订单</van-button
        >
        <van-button :to="`/room?orderId=${order?.roomId}`">返回诊室</van-button>
      </div>
    </div>
    <div class="content" v-else>
      <van-icon name="checked" color="#68c1a1" size="60" />
      <p class="price">￥35.00</p>
      <p>支付成功</p>
      <p class="success" style="margin-top: 20px">
        订单支付成功，已通知药房尽快发出，请耐心等待~
      </p>
      <div class="btn">
        <van-button type="primary" :to="`/order/${order?.id}`"
          >查看订单</van-button
        >
        <van-button :to="{ name: 'ConsultRoom', query: roomConfig }"
          >返回诊室</van-button
        >
      </div>
    </div>
  </div>
</template>

<style lang="scss" scoped>
.pay-result-page {
  margin-top: 46px;
  .content {
    padding-top: 50px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    .price {
      font-size: 20px;
      font-weight: 600;
      margin-top: 10px;
    }
    .success {
      font-size: 12px;
      color: #cfcfd0;
      margin-top: 20px;
    }
    .btn {
      margin-top: 40px;
      .van-button {
        width: 90px;
        font-size: 14px;
        margin: 0 10px;
      }
    }
  }
}
</style>
